package com.ruoyi.system.domain;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Tree {

    //封装科室上下级关系
    public static List<Department> departmentsToTree(List<Department> departmentList){
        Map<Long, List<Department>> groupMap = departmentList.stream().collect(Collectors.groupingBy(Department::getPid));
        departmentList.forEach(department -> {
            department.setDepartment(groupMap.get(department.getId()));
        });
        List<Department> collect = departmentList.stream().filter(department -> department.getPid().equals(0L)).collect(Collectors.toList());
        return collect;
    }

//    //封装部门树
//    public static List<SysDept> deptTree(List<SysDept> treeList) {
//        //操作所有组织机构数据
//        Map<Long, List<SysDept>> groupMap = treeList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
//        treeList.forEach(sysDept-> {
////            sysDept.setChildDept(groupMap.get(sysDept.getDeptId()));
//        });
//        List<SysDept> collect = treeList.stream().filter(sysDept-> sysDept.getParentId().equals(0L)).collect(Collectors.toList());
//        return collect;
//    }


}
